import { reqUserInfo } from '@/api/login'
import { ElMessage } from 'element-plus'
import { defineStore } from 'pinia'


export const useUserInfoStore = defineStore('userInfoStore', {
  state:()=>{
    return {
        token:'',
        nickName:''
    }
  },
  actions:{
    getUserInfo(token:string,nickName:string){
     this.token= token
     this.nickName = nickName
    },
    
    async getInfo(){

      try {
        const res =  await reqUserInfo()
      
        if (res.code === 200) {
          this.nickName = res.data.nickName
        }
      } catch (error) {
        ElMessage.error('退出登录')
        ElMessage.closeAll()
        
        
      }
      
      // console.log(res);
      
      // if (res.code === 200) {
      //   this.nickName = res.data.nickName
      // }

      // this.nickName = res.data.nickName
      // console.log(res);
      
    },
    // 删除用户信息
    getDelInfo(){
      this.nickName = ''
    }
  
  },
  getters:{}
}) 
export default useUserInfoStore